﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhSystemBLL.orderData;
using dhSystemBLL.produceBLL;
using dhDataAcess.produceLinq;
using baseSet;
using dhDataAcess.baseBLL;

namespace dhsystem.produceForm.picking
{
    public partial class FrmpdpqbAdd : Form
    {
        string state;
        string orderDetailNo;
        BindingSource b2;
        pdpqbBLL pdpqb = new pdpqbBLL();
        pdpqbModel pdpqbRow = new pdpqbModel();
        string billoNo;
        public FrmpdpqbAdd(string _state, BindingSource b1, string _orderDetailNo, string _billoNo)
        {
            InitializeComponent();
            state = _state;
            b2 = b1;
            orderDetailNo = _orderDetailNo;
            billoNo = _billoNo;
        }
        orderDetailBLL orderDetail = new orderDetailBLL();
      
        private void FrmpdpqbAdd_Load(object sender, EventArgs e)
        {
            if (state == "欠数")
            {
                orderDetailBLL orderDetail = new orderDetailBLL();
                bindingSourceorderDetail.DataSource = orderDetail.getorderDetailAllByorderDetailNo(orderDetailNo);
                pbomMarkBLL pbomMark = new pbomMarkBLL();

                textorderDetailNo.DataBindings.Add("text", bindingSourceorderDetail, "orderDetailNo");
                textpname.DataBindings.Add("text", bindingSourceorderDetail, "pname");
                textcolor.DataBindings.Add("text", bindingSourceorderDetail, "pcolor");
                textsehao.DataBindings.Add("text", bindingSourceorderDetail, "colorNum");
                textunit.DataBindings.Add("text", bindingSourceorderDetail, "unit");
                textorderQty.DataBindings.Add("text", bindingSourceorderDetail, "qty");
                textorderDate.DataBindings.Add("text", b2, "orderDate");
                textreceiveDate.DataBindings.Add("text", b2, "receiveDate");
                textcustPo.DataBindings.Add("text", b2, "custPoNo");

                bSourcepbomMark.DataSource = pbomMark.getpbomMarkAllBypname(textpname.Text);
                textpdopen.DataBindings.Add("text", bSourcepbomMark, "startopen");
                textproductopen.DataBindings.Add("text", bSourcepbomMark, "endopen");
            }
            if (state =="新增")
            {
            orderDetailBLL orderDetail = new orderDetailBLL();
            bindingSourceorderDetail.DataSource = orderDetail.getorderDetailAllByorderDetailNo(orderDetailNo);
            pbomMarkBLL pbomMark = new pbomMarkBLL();
            
            textorderDetailNo.DataBindings.Add("text", bindingSourceorderDetail, "orderDetailNo");
            textpname.DataBindings.Add("text", bindingSourceorderDetail, "pname");
            textcolor.DataBindings.Add("text", bindingSourceorderDetail, "pcolor");
            textsehao.DataBindings.Add("text", bindingSourceorderDetail, "colorNum");
            textunit.DataBindings.Add("text", bindingSourceorderDetail, "unit");
            textorderQty.DataBindings.Add("text", bindingSourceorderDetail, "qty");
            textorderDate.DataBindings.Add("text", b2, "orderDate");
            textreceiveDate.DataBindings.Add("text", b2, "receiveDate");
            textcustPo.DataBindings.Add("text", b2, "custPoNo");

            bSourcepbomMark.DataSource = pbomMark.getpbomMarkAllBypname (textpname.Text);
            textpdopen.DataBindings.Add("text", bSourcepbomMark, "startopen");
            textproductopen.DataBindings.Add("text", bSourcepbomMark, "endopen");
        }
            if (state == "编辑")
            {
                textorderDetailNo.DataBindings.Add("text", b2, "orderDetailNo");
                textpname.DataBindings.Add("text", b2, "pname");
                textcolor.DataBindings.Add("text", b2, "pcolor");
                textsehao.DataBindings.Add("text", b2, "colorNum");
                textunit.DataBindings.Add("text", b2, "unit");
                textorderQty.DataBindings.Add("text", b2, "qty");
                textorderDate.DataBindings.Add("text", b2, "orderDate");
                textreceiveDate.DataBindings.Add("text", b2, "receiveDate");
                textcustPo.DataBindings.Add("text", b2, "custPoNo");
                datepiaoranDate.DataBindings.Add("text", b2, "piaoranDate");
                textmachineNo.DataBindings.Add("text", b2, "machineNo");
                textpdopen.DataBindings.Add("text", b2, "pdopen");
                textmark.DataBindings.Add("text", b2, "mark");
                textqty.DataBindings.Add("text", b2, "yuqty");
                textproductopen.DataBindings.Add("text", b2, "productopen");
               
            }
            if (state == "欠数编辑")
            {
                textorderDetailNo.DataBindings.Add("text", b2, "orderDetailNo");
                textpname.DataBindings.Add("text", b2, "pname");
                textcolor.DataBindings.Add("text", b2, "pcolor");
                textsehao.DataBindings.Add("text", b2, "colorNum");
                textunit.DataBindings.Add("text", b2, "unit");
                textorderQty.DataBindings.Add("text", b2, "qty");
                textorderDate.DataBindings.Add("text", b2, "orderDate");
                textreceiveDate.DataBindings.Add("text", b2, "receiveDate");
                textcustPo.DataBindings.Add("text", b2, "custPoNo");
                datepiaoranDate.DataBindings.Add("text", b2, "piaoranDate");
                textmachineNo.DataBindings.Add("text", b2, "machineNo");
                textpdopen.DataBindings.Add("text", b2, "pdopen");
                textmark.DataBindings.Add("text", b2, "mark");
                textqty.DataBindings.Add("text", b2, "yuqty");
                textproductopen.DataBindings.Add("text", b2, "productopen");

            }
            textmachineNo.Focus();
          //  textpdkucun.Text = basicSql.getstockQty(textpname.Text );
        }

        private void label17_Click(object sender, EventArgs e)
        {

        }

        private void toolSave_Click(object sender, EventArgs e)
        {
            if (state == "新增")
            {
                try
                {
                    DialogResult result = MessageBox.Show("是否保存资料！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        pdpqbRow.billoNo = "D" + GlobalInfo.Date + "-" + basicSql.getOrderSerail("排期号");
                        pdpqbRow.machineNo = textmachineNo.Text;
                        pdpqbRow.mark = textmark.Text;
                        pdpqbRow.orderDetailNo = textorderDetailNo.Text;
                        pdpqbRow.pdenough = true ;
                        pdpqbRow.pdfw ="";
                        pdpqbRow.pdopen = textpdopen.Text;
                        pdpqbRow.piaoranDate = datepiaoranDate.Value;
                        pdpqbRow.pname = textpname.Text;
                        pdpqbRow.productopen = textproductopen.Text;
                        pdpqbRow.unit = textunit.Text;
                        pdpqbRow.yuqty = 0;
                        pdpqbRow.dyeDate = DateTime.Now;
                        pdpqbRow.dyestatus = "";
                        pdpqbRow.billStatus  = "开始染色";
                        pdpqbRow.createDate = DateTime.Now;
                        pdpqbRow.createUser = GlobalInfo.UserName;
                        pdpqbRow.updateDate = DateTime.Now;
                        pdpqbRow.updateUser = GlobalInfo.UserName;
                        pdpqbRow.yuqty   =0 ;
                        pdpqb.pdpqbInsert (pdpqbRow);
                        basicSql.getdetailStatusUpdate(orderDetailNo ,"开始染色");
                        MessageBox.Show("新增成功");
                        this.Close();
                    }
                }
                catch (FormatException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            if (state == "欠数")
            {
                try
                {
                    DialogResult result = MessageBox.Show("是否保存资料！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        pdpqbRow.billoNo = "D" + GlobalInfo.Date + "-" + basicSql.getOrderSerail("排期号");
                        pdpqbRow.machineNo = textmachineNo.Text;
                        pdpqbRow.mark = "欠数";
                        pdpqbRow.orderDetailNo = textorderDetailNo.Text;
                        pdpqbRow.pdenough = true;
                        pdpqbRow.pdfw = "";
                        pdpqbRow.pdopen = textpdopen.Text;
                        pdpqbRow.piaoranDate = datepiaoranDate.Value;
                        pdpqbRow.pname = textpname.Text;
                        pdpqbRow.productopen = textproductopen.Text;
                        pdpqbRow.unit = textunit.Text;
                        pdpqbRow.yuqty = 0;
                        pdpqbRow.dyeDate = DateTime.Now;
                        pdpqbRow.dyestatus = "";
                        pdpqbRow.billStatus = "欠数";
                        pdpqbRow.createDate = DateTime.Now;
                        pdpqbRow.createUser = GlobalInfo.UserName;
                        pdpqbRow.updateDate = DateTime.Now;
                        pdpqbRow.updateUser = GlobalInfo.UserName;
                        pdpqbRow.yuqty = Convert.ToDecimal(textqty.Text);
                        pdpqb.pdpqbInsert(pdpqbRow);
                        basicSql.getdetailStatusUpdate(orderDetailNo, "欠数染色");
                        MessageBox.Show("新增成功");
                        this.Close();
                    }
                }
                catch (FormatException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            if (state == "编辑")
            {
                try
                {
                    DialogResult result = MessageBox.Show("是否修改资料！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        pdpqbRow.billoNo = billoNo;
                        pdpqbRow.machineNo = textmachineNo.Text;
                        pdpqbRow.mark = textmark.Text;
                        pdpqbRow.orderDetailNo = textorderDetailNo.Text;
                       pdpqbRow.pdenough = true ;
                        pdpqbRow.pdfw = "";
                        pdpqbRow.pdopen = textpdopen.Text;
                        pdpqbRow.piaoranDate = datepiaoranDate.Value;
                        pdpqbRow.pname = textpname.Text;
                        pdpqbRow.productopen = textproductopen.Text;
                        pdpqbRow.unit = textunit.Text;
                        pdpqbRow.yuqty = 0;
                        pdpqbRow.dyeDate = DateTime.Now;
                        pdpqbRow.dyestatus = "";
                        pdpqbRow.billStatus = basicSql.getpdpqbblStatus(billoNo);
                        pdpqbRow.createDate = DateTime.Now;
                        pdpqbRow.createUser = GlobalInfo.UserName;
                        pdpqbRow.updateDate = DateTime.Now;
                        pdpqbRow.updateUser = GlobalInfo.UserName;
                        pdpqb.pdpqbUpdate (pdpqbRow);

                        MessageBox.Show("修改成功");

                    }
                }
                catch (FormatException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            if (state == "欠数编辑")
            {
                try
                {
                    DialogResult result = MessageBox.Show("是否修改资料！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        pdpqbRow.billoNo = billoNo;
                        pdpqbRow.machineNo = textmachineNo.Text;
                        pdpqbRow.mark = textmark.Text;
                        pdpqbRow.orderDetailNo = textorderDetailNo.Text;
                        pdpqbRow.pdenough = true;
                        pdpqbRow.pdfw = "";
                        pdpqbRow.pdopen = textpdopen.Text;
                        pdpqbRow.piaoranDate = datepiaoranDate.Value;
                        pdpqbRow.pname = textpname.Text;
                        pdpqbRow.productopen = textproductopen.Text;
                        pdpqbRow.unit = textunit.Text;
                        pdpqbRow.yuqty = 0;
                        pdpqbRow.dyeDate = DateTime.Now;
                        pdpqbRow.dyestatus = "";
                        pdpqbRow.billStatus = "欠数";
                        pdpqbRow.createDate = DateTime.Now;
                        pdpqbRow.createUser = GlobalInfo.UserName;
                        pdpqbRow.updateDate = DateTime.Now;
                        pdpqbRow.updateUser = GlobalInfo.UserName;
                        pdpqbRow.yuqty = Convert.ToDecimal(textqty.Text);
                        pdpqb.pdpqbUpdate(pdpqbRow);

                        MessageBox.Show("修改成功");

                    }
                }
                catch (FormatException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }

        private void textpname_TextChanged(object sender, EventArgs e)
        {
            labelpwight.Text = basicSql.getgrwightbyproductList (textpname .Text );
            textpdkucun.Text = basicSql.getstockQty(textpname.Text);
        }


    }
}
